import pytest,allure
from damai.pages.v5crmeb import v5
from damai.utils.driver import *
from damai.utils.log import *

@pytest.fixture()
def createV5():
    v_ = v5()
    yield v_

@pytest.hookimpl(hookwrapper=True) #注册钩子函数
def pytest_runtest_makereport(item):
    outcome=yield #获取用例执行返回的结果集数据
    result=outcome.get_result() #从结果集数据中获取用例的执行情况
    #print(result)
    #print(result.when) # 有三个值：setup,call,teardown
    if result.when=='call' and result.outcome=='failed':
        logger.error(f'失败报错信息：{result.longrepr}')
        #判断用例是否被执行，如果执行失败，则把截图添加到报告当中
        logger.debug('失败截图并添加到报告中')
        allure.attach(get_driver('edge').get_screenshot_as_png(),'失败截图',allure.attachment_type.PNG)
